package com.zichuan;

/**
 * @author zichuan
 * @version 1.0
 * @Package : com.zichuan
 * @Description : TODO
 * @Create on : 2025/2/19 12:02
 */
public class StringCode {

    /**
     * 将ip转为10进制数
     * @param ip 10.0.3.193
     * @return
     */
    public Long convert(String ip){
        String[] split = ip.split(".");
        StringBuilder builder = new StringBuilder();
        for (String s : split) {//10进制转2进制
            int num = Integer.parseInt(s);  // 拆分
            String num2 = Integer.toBinaryString(num);  //转换为二进制
            while(num2.length()<8){
                num2 = "0" + num2;  // 拼接
            }
            builder.append(num2);
        }
        return Long.parseLong(builder.toString(), 2);  // 转化为10进制
    }
}
